package com.ljkj.cordial.chat.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.ljkj.cordial.chat.R;
import com.ljkj.cordial.chat.bean.SearchBean;
import com.nic.view.adapter.CommonAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 添加好友
 */
public class SearchFriendAdapter extends CommonAdapter<SearchBean> {
    @Override
    public View getBindView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_search_friend, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        SearchBean item = (SearchBean) getItem(position);
        if (SearchBean.FRIEND == item.getType()) {
//            R.mipmap.ic_search_friend
            holder.tvTypeAvatar.setImageResource(R.mipmap.list_addfriend);
            holder.tvSearchContent.setText(String.format("搜索好友\"%s\"", item.getContent()));
        } else if (SearchBean.GROUP == item.getType()) {
//            R.mipmap.ic_search_group
            holder.tvTypeAvatar.setImageResource(R.mipmap.list_addgroup);
            holder.tvSearchContent.setText(String.format("搜索群\"%s\"", item.getContent()));
        }

        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.tv_type_avatar)
        ImageView tvTypeAvatar;
        @BindView(R.id.tv_search_content)
        TextView tvSearchContent;


        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
